package org.ohuyo.libra.client.util;

import javax.servlet.ServletContext;

import org.ohuyo.libra.client.config.MasterClientConfig;
import org.ohuyo.libra.client.config.SlaveClientConfig;
import org.ohuyo.libra.client.service.MasterClientService;
import org.ohuyo.libra.client.service.SlaveClientService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 
 * @author rabbit
 * 
 */
public class ServiceUtils {
	public static MasterClientService getMasterClientService(
			ServletContext context) {
		return (MasterClientService) getBean(context,
				"org.ohuyo.libra.client.master.masterClientService");

	}

	public static MasterClientConfig getMasterClientConfig(
			ServletContext context) {
		return (MasterClientConfig) getBean(context,
				"org.ohuyo.libra.client.master.config");

	}

	public static SlaveClientService getSlaveClientService(
			ServletContext context) {
		return (SlaveClientService) getBean(context,
				"org.ohuyo.libra.client.slave.slaveClientService");

	}

	public static SlaveClientConfig getSlaveClientConfig(ServletContext context) {
		return (SlaveClientConfig) getBean(context,
				"org.ohuyo.libra.client.slave.config");

	}

	public static Object getBean(ServletContext context, String name) {
		WebApplicationContext wac = WebApplicationContextUtils
				.getWebApplicationContext(context);
		return wac.getBean(name);
	}
}
